<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<link rel="stylesheet" type="text/css" href="../scripts/ext-3.3.1/resources/css/ext-all.css"/>
	<link rel="stylesheet" type="text/css" href="../styles/global.css"/>
	<script type="text/javascript" src="../scripts/ext-3.3.1/adapter/ext/ext-base.js"></script>
	<script type="text/javascript" src="../scripts/ext-3.3.1/ext-all.js"></script>
	<script type="text/javascript" src="../scripts/extjs-plus.js"></script>
<title></title>
<script type="text/javascript">
	Ext.onReady(function(){
		var sm = new Ext.grid.CheckboxSelectionModel();
		var options = {
			title:"下载历史",
			cm:new Ext.grid.ColumnModel([
				new Ext.grid.RowNumberer(),
				sm,
				{header:"任务",width:350,sortable:true,dataIndex:"id",id:"id",hidden:true},
				{header:"任务",width:350,sortable:true,dataIndex:"title"},
	           	{header:"执行时间",width:180,sortable:true,dataIndex:"startTime"},
	           	{header:"耗时",align:'right',width:100,sortable:true,dataIndex:"useTime",renderer:function(v){return v+"分钟";}},
				{header:"下载数量",align:'right',width:100,sortable:true,dataIndex:"count",renderer:function(v){return Ext.util.Format.number(v,'0,000');}},
				{header:"执行结果",sortable:true,dataIndex:"result",id:"result"}
	        ]),
			record:new Ext.data.Record.create([
			    {name:"id",type:"int"},
               	{name:"index",type:"int"},
            	{name:"title",type:"string"},
            	{name:"startTime",type:"string"},
             	{name:"useTime",type:"string"},
            	{name:"count",type:"string"},
            	{name:"result",type:"string"}
			]),
            url:"<s:url action='admin/download_log'/>",
            start:0,
            sm:sm,
            limit:20,
            autoExpandColumnId:"result",
            showBottomBar:true,
            tbar:[{
            	text:"删除",
            	icon:"../scripts/ext-3.3.1/resources/images/default/dd/drop-delete.gif",
            	handler:function(){
            		var view = gridpanel.getView();
            		var store = gridpanel.getStore();
            		var sm = gridpanel.getSelectionModel();
            		var ids = [];
            		for(var i=0;i<view.getRows().length;i++){
            			if(sm.isSelected(i)){
            				ids.push(store.getAt(i).get("id"));
            			}
            		}
            		download_delete(ids);
            	}
            }]
		};
		
		gridpanel = create_gridpanel(options).render("log");
	});
	
	function download_delete(ids){
		if(ids.length>0){
			Ext.MessageBox.confirm("删除","确定要删除吗？",function(btn,txt){
				if(btn=='no'){
					return false;
				}
				Ext.Ajax.request({
					url:"<s:url action='admin/download_delete'/>",
					params:{ids:Ext.util.JSON.encode(ids)},
					method:"post",
					success:function(response,config){
						if(response.responseText==1){
							gridpanel.getStore().reload();
						}else{
							Ext.MessageBox.alert("错误","删除失败，请联系管理员!");
						}
					},
					failure:function(response,config){
						Ext.MessageBox.alert("错误","删除失败，请稍候再试!");
					}
				});
			});
		}else{
			Ext.MessageBox.alert("错误","请选择要删除的行!");
		}
	}
</script>
</head>
<body>
<div id="log"></div>
</body>
</html>